home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / msword1a / wbrwordd.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1999-08-27  |  23.5 KB  |  694 lines

  1. VERSION 5.00
  2. Object = "{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}#1.1#0"; "SHDOCVW.DLL"
  3. Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
  4. Begin VB.Form frmWbrWordDemo 
  5.    Caption         =   "Word Demo"
  6.    ClientHeight    =   3510
  7.    ClientLeft      =   60
  8.    ClientTop       =   630
  9.    ClientWidth     =   5280
  10.    MDIChild        =   -1  'True
  11.    MinButton       =   0   'False
  12.    ScaleHeight     =   3510
  13.    ScaleWidth      =   5280
  14.    WindowState     =   2  'Maximized
  15.    Begin MSComctlLib.StatusBar sta 
  16.       Align           =   2  'Align Bottom
  17.       Height          =   315
  18.       Left            =   0
  19.       TabIndex        =   1
  20.       Top             =   3195
  21.       Width           =   5280
  22.       _ExtentX        =   9313
  23.       _ExtentY        =   556
  24.       Style           =   1
  25.       _Version        =   393216
  26.       BeginProperty Panels {8E3867A5-8586-11D1-B16A-00C0F0283628} 
  27.          NumPanels       =   1
  28.          BeginProperty Panel1 {8E3867AB-8586-11D1-B16A-00C0F0283628} 
  29.          EndProperty
  30.       EndProperty
  31.    End
  32.    Begin SHDocVwCtl.WebBrowser wbr 
  33.       Height          =   2475
  34.       Left            =   360
  35.       TabIndex        =   0
  36.       Top             =   360
  37.       Width           =   4515
  38.       ExtentX         =   7964
  39.       ExtentY         =   4366
  40.       ViewMode        =   1
  41.       Offline         =   0
  42.       Silent          =   0
  43.       RegisterAsBrowser=   0
  44.       RegisterAsDropTarget=   0
  45.       AutoArrange     =   -1  'True
  46.       NoClientEdge    =   0   'False
  47.       AlignLeft       =   0   'False
  48.       ViewID          =   "{0057D0E0-3573-11CF-AE69-08002B2E1262}"
  49.       Location        =   ""
  50.    End
  51.    Begin VB.Menu mnuFileMenu 
  52.       Caption         =   "&File"
  53.       Begin VB.Menu mnuFile 
  54.          Caption         =   "&Open..."
  55.          Index           =   0
  56.       End
  57.       Begin VB.Menu mnuFile 
  58.          Caption         =   "&Close"
  59.          Index           =   1
  60.       End
  61.       Begin VB.Menu mnuFile 
  62.          Caption         =   "-"
  63.          Index           =   2
  64.       End
  65.       Begin VB.Menu mnuFile 
  66.          Caption         =   "&Save"
  67.          Index           =   3
  68.       End
  69.       Begin VB.Menu mnuFile 
  70.          Caption         =   "Save &As..."
  71.          Index           =   4
  72.       End
  73.       Begin VB.Menu mnuFile 
  74.          Caption         =   "Save as &HTML..."
  75.          Index           =   5
  76.       End
  77.       Begin VB.Menu mnuFile 
  78.          Caption         =   "-"
  79.          Index           =   6
  80.       End
  81.       Begin VB.Menu mnuFile 
  82.          Caption         =   "Page Set&up..."
  83.          Index           =   7
  84.       End
  85.       Begin VB.Menu mnuFile 
  86.          Caption         =   "&Print..."
  87.          Index           =   8
  88.          Shortcut        =   ^P
  89.       End
  90.       Begin VB.Menu mnuFile 
  91.          Caption         =   "-"
  92.          Index           =   9
  93.       End
  94.       Begin VB.Menu mnuFile 
  95.          Caption         =   "Properties"
  96.          Index           =   10
  97.          Begin VB.Menu mnuFileProps 
  98.             Caption         =   "Summary Info"
  99.             Index           =   0
  100.          End
  101.          Begin VB.Menu mnuFileProps 
  102.             Caption         =   "Word Count"
  103.             Index           =   1
  104.          End
  105.       End
  106.       Begin VB.Menu mnuFile 
  107.          Caption         =   "-"
  108.          Index           =   11
  109.       End
  110.       Begin VB.Menu mnuFile 
  111.          Caption         =   "Close &Window"
  112.          Index           =   12
  113.       End
  114.       Begin VB.Menu mnuFile 
  115.          Caption         =   "&Format HTML"
  116.          Index           =   13
  117.       End
  118.    End
  119.    Begin VB.Menu mnuViewMenu 
  120.       Caption         =   "&View"
  121.       Enabled         =   0   'False
  122.       Begin VB.Menu mnuView 
  123.          Caption         =   "Normal View"
  124.          Index           =   0
  125.       End
  126.       Begin VB.Menu mnuView 
  127.          Caption         =   "Page Layout"
  128.          Index           =   1
  129.       End
  130.       Begin VB.Menu mnuView 
  131.          Caption         =   "-"
  132.          Index           =   2
  133.       End
  134.       Begin VB.Menu mnuView 
  135.          Caption         =   "Horizontal Scroll"
  136.          Index           =   3
  137.       End
  138.       Begin VB.Menu mnuView 
  139.          Caption         =   "Ruler"
  140.          Index           =   4
  141.       End
  142.       Begin VB.Menu mnuView 
  143.          Caption         =   "Toolbars"
  144.          Index           =   5
  145.          Begin VB.Menu mnuViewToolbar 
  146.             Caption         =   "Standard"
  147.             Index           =   0
  148.          End
  149.          Begin VB.Menu mnuViewToolbar 
  150.             Caption         =   "Formatting"
  151.             Index           =   1
  152.          End
  153.          Begin VB.Menu mnuViewToolbar 
  154.             Caption         =   "Drawing"
  155.             Index           =   2
  156.          End
  157.          Begin VB.Menu mnuViewToolbar 
  158.             Caption         =   "Reviewing"
  159.             Index           =   3
  160.          End
  161.       End
  162.    End
  163.    Begin VB.Menu mnuToolsMenu 
  164.       Caption         =   "&Tools"
  165.       Enabled         =   0   'False
  166.       Begin VB.Menu mnuTools 
  167.          Caption         =   "&Spelling"
  168.          Index           =   0
  169.       End
  170.       Begin VB.Menu mnuTools 
  171.          Caption         =   "&Thesaurus..."
  172.          Index           =   1
  173.       End
  174.       Begin VB.Menu mnuTools 
  175.          Caption         =   "&Options"
  176.          Index           =   2
  177.          Begin VB.Menu mnuOpt 
  178.             Caption         =   "Show All"
  179.             Index           =   0
  180.          End
  181.          Begin VB.Menu mnuOpt 
  182.             Caption         =   "Status Bar"
  183.             Checked         =   -1  'True
  184.             Index           =   1
  185.          End
  186.       End
  187.    End
  188.    Begin VB.Menu mnuDemoMenu 
  189.       Caption         =   "&Demo"
  190.       Enabled         =   0   'False
  191.       Begin VB.Menu mnuDemo 
  192.          Caption         =   "&Title"
  193.          Index           =   0
  194.       End
  195.       Begin VB.Menu mnuDemo 
  196.          Caption         =   "&SubTitle"
  197.          Index           =   1
  198.       End
  199.       Begin VB.Menu mnuDemo 
  200.          Caption         =   "&Data"
  201.          Index           =   2
  202.       End
  203.       Begin VB.Menu mnuDemo 
  204.          Caption         =   "&Notes"
  205.          Index           =   3
  206.       End
  207.       Begin VB.Menu mnuDemo 
  208.          Caption         =   "-"
  209.          Index           =   4
  210.       End
  211.       Begin VB.Menu mnuDemo 
  212.          Caption         =   "&All"
  213.          Index           =   5
  214.       End
  215.    End
  216. Attribute VB_Name = "frmWbrWordDemo"
  217. Attribute VB_GlobalNameSpace = False
  218. Attribute VB_Creatable = False
  219. Attribute VB_PredeclaredId = True
  220. Attribute VB_Exposed = False
  221. Option Explicit
  222. ' WbrWordDemo.frm v1.00 (Vb6) Apr 1999  Contact markb@orionstudios.com
  223. ' Adapted from WbrWord.frm to demonstrate manipulation of
  224. '   MS Word Document contained by a WebBrowser Control.
  225. ' Requires provided sample files (see constants DEMO_DOC and DEMO_DAT)
  226. '=================================================================================
  227. ' Module-level Variables
  228. Private MARGINx2 As Long
  229. Private mTopUsedArea As Long    ' varies with ToolBar/Captions visibility
  230. Private mBotUsedArea As Long    ' varies with StatusBar visibility
  231. Private mVertUsedArea As Long   ' = mTopUsedArea + mBotUsedArea
  232. Private mDoc As Word.Document   ' Word Document contained by WebBrowser Control
  233. Private mDocURL As String       ' URL of Word Document contained by WebBrowser Control
  234. Private mFilePath As String     '<== Demo
  235. ' Module-level Constants
  236. Private Const MARGIN = 0        ' set as required (Twips)
  237. Private Const DEMO_DOC = "WbrWordDemo.doc"  ' template with Bookmarks defined
  238. Private Const DEMO_DAT = "WbrWordDemo.txt"  ' for Word InsertFile Method
  239. Private Const TITLE_BODY = "<BODY SCROLL=NO>" _
  240.             & "MS Word<BR>Document<BR>Container" _
  241.             & "<DIV ID=idDIV>(Hint: try File/Format HTML/or open)</DIV>" _
  242.             & "</BODY>"
  243. Private Const TITLE_PAGE = "about:" & TITLE_BODY
  244. ' Browser navigation constants
  245. Private Const navNoHistory = 2
  246. Private Const navNoReadFromCache = 4
  247. Private Const navNoWriteToCache = 8
  248. Private Const mNavFlags = navNoHistory Or navNoReadFromCache Or navNoWriteToCache
  249. ' File Menu constants
  250. Private Const FILE_OPEN = 0
  251. Private Const FILE_CLOSE = 1
  252. Private Const FILE_SAVE = 3
  253. Private Const FILE_SAVEAS = 4
  254. Private Const FILE_SAVEASHTML = 5
  255. Private Const FILE_PAGESETUP = 7
  256. Private Const FILE_PRINT = 8
  257. Private Const FILE_PROPS = 10
  258. Private Const FILE_CLOSEWIN = 12
  259. Private Const FILE_FORMAT = 13  '<== Demo
  260. ' Properties Menu constants
  261. Private Const PROP_SUMMARY = 0
  262. Private Const PROP_WORDCOUNT = 1
  263. ' View Menu constants
  264. Private Const VIEW_NORMAL = 0
  265. Private Const VIEW_PAGE = 1
  266. Private Const VIEW_HSCROLL = 3
  267. Private Const VIEW_RULER = 4
  268. ' Tool Menu constants
  269. Private Const TOOLS_SPELL = 0
  270. Private Const TOOLS_THESAURUS = 1
  271. Private Const TOOLS_OPTIONS = 2
  272. ' Option Menu constants
  273. Private Const OPT_SHOWALL = 0
  274. Private Const OPT_STATUSBAR = 1
  275. ' Demo Menu Constants
  276. Private Const DEMO_TITLE = 0
  277. Private Const DEMO_SUBTITLE = 1
  278. Private Const DEMO_DATA = 2
  279. Private Const DEMO_NOTES = 3
  280. Private Const DEMO_ALL = 5
  281. Private Sub Form_Load()
  282.     MARGINx2 = MARGIN * 2
  283.     mTopUsedArea = MARGIN   ' + VB toolbar height, if present
  284.     mBotUsedArea = sta.Height
  285.     mVertUsedArea = mTopUsedArea + mBotUsedArea
  286.     mFilePath = App.Path & "\"   '<== Demo
  287.     wbr.Navigate TITLE_PAGE, mNavFlags
  288. End Sub
  289. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
  290.     '<== Demo
  291.     If UnloadMode <> vbFormCode Then
  292.         If mnuViewMenu Then ' Word doc is currently in browser
  293.             Cancel = True
  294.             MsgBox "Please use the File Menu to close", _
  295.                     vbExclamation, _
  296.                     "Closing Demo..."
  297.         End If
  298.     End If
  299.     '<== Demo
  300. End Sub
  301. Private Sub Form_Resize()
  302.     On Error Resume Next
  303.     wbr.Move MARGIN, mTopUsedArea, Me.ScaleWidth - MARGINx2, Me.ScaleHeight - mVertUsedArea
  304. End Sub
  305. Private Sub mnuFileMenu_Click()
  306.     Dim IsWordDoc As Boolean
  307.     Dim IsSaved As Boolean
  308.     IsWordDoc = Not (mDoc Is Nothing)
  309.     If IsWordDoc Then
  310.         IsSaved = mDoc.Saved
  311.     End If
  312.     mnuFile(FILE_CLOSE) = IsWordDoc
  313.     mnuFile(FILE_SAVE) = False  '<== Demo
  314.     mnuFile(FILE_SAVEAS) = IsWordDoc
  315.     mnuFile(FILE_SAVEASHTML) = IsWordDoc
  316.     mnuFile(FILE_PAGESETUP) = IsWordDoc
  317.     mnuFile(FILE_PRINT) = IsWordDoc
  318.     mnuFile(FILE_PROPS) = IsWordDoc
  319.     mnuFile(FILE_CLOSEWIN) = IsSaved Or Not IsWordDoc
  320. End Sub
  321. Private Sub mnuFile_Click(Index As Integer)
  322.     On Error Resume Next
  323.     Select Case Index
  324.         Case FILE_OPEN
  325.             wbr.Navigate mFilePath & DEMO_DOC, mNavFlags  '<== Demo
  326.             
  327.         Case FILE_CLOSE
  328.             mDoc.Saved = True   '<== Demo
  329.             wbr.Navigate TITLE_PAGE, mNavFlags  ' removes Word document but
  330.                                                 ' DOES NOT close Word instance
  331.         Case FILE_SAVE
  332.             wbr.ExecWB _
  333.                 cmdID:=OLECMDID_SAVE, _
  334.                 cmdexecopt:=OLECMDEXECOPT_PROMPTUSER
  335.                 
  336.         Case FILE_SAVEAS
  337.             wbr.ExecWB _
  338.                 cmdID:=OLECMDID_SAVEAS, _
  339.                 cmdexecopt:=OLECMDEXECOPT_PROMPTUSER
  340.                 
  341.         Case FILE_SAVEASHTML
  342.             FileSaveAsHTML
  343.             
  344.         Case FILE_PAGESETUP
  345.             wbr.ExecWB _
  346.                 cmdID:=OLECMDID_PAGESETUP, _
  347.                 cmdexecopt:=OLECMDEXECOPT_PROMPTUSER
  348.                 
  349.         Case FILE_PRINT
  350.             wbr.ExecWB _
  351.                 cmdID:=OLECMDID_PRINT, _
  352.                 cmdexecopt:=OLECMDEXECOPT_PROMPTUSER
  353.                 
  354.         Case FILE_CLOSEWIN
  355.             Unload Me
  356.             
  357.         Case FILE_FORMAT    '<== Demo
  358.             FormatTitlePage
  359.             mnuFile(FILE_FORMAT).Visible = False
  360.             
  361.     End Select
  362. End Sub
  363. Private Sub mnuFileProps_Click(Index As Integer)
  364. ' See VbaWrd8.HLP for distinction between "Show" and "Display" methods
  365.     On Error Resume Next
  366.     Select Case Index
  367.         Case PROP_SUMMARY  ' Word Document Summary Info
  368.             mDoc.Application.Dialogs(wdDialogFileSummaryInfo).Show
  369.             
  370.         Case PROP_WORDCOUNT  ' Word Document Word Count (display only)
  371.             mDoc.Application.Dialogs(wdDialogToolsWordCount).Display
  372.             
  373.     End Select
  374.         
  375. End Sub
  376. Private Sub mnuViewMenu_Click()
  377.     On Error Resume Next
  378.     Dim mnu As Menu
  379.     With mDoc
  380.         With .ActiveWindow
  381.             mnuView(VIEW_NORMAL).Checked = (.View.Type = wdNormalView)
  382.             mnuView(VIEW_PAGE).Checked = (.View.Type = wdPageView)
  383.             mnuView(VIEW_HSCROLL).Checked = .DisplayHorizontalScrollBar
  384.             mnuView(VIEW_RULER).Checked = .DisplayRulers
  385.         End With
  386.         
  387.         For Each mnu In mnuViewToolbar  ' Assumes Menu captions match Toolbar names
  388.             mnu.Checked = .CommandBars(mnu.Caption).Visible
  389.         Next
  390.         
  391.     End With
  392. End Sub
  393. Private Sub mnuView_Click(Index As Integer)
  394.     On Error Resume Next
  395.     With mDoc.ActiveWindow
  396.         Select Case Index
  397.         
  398.             Case VIEW_NORMAL
  399.                 .View.Type = wdNormalView
  400.                 
  401.             Case VIEW_PAGE
  402.                 .View.Type = wdPageView
  403.                 
  404.             Case VIEW_HSCROLL
  405.                 .DisplayHorizontalScrollBar = Not .DisplayHorizontalScrollBar
  406.                 
  407.             Case VIEW_RULER
  408.                .DisplayRulers = Not .DisplayRulers
  409.           
  410.         End Select
  411.     End With
  412. End Sub
  413. Private Sub mnuViewToolbar_Click(Index As Integer)
  414.     On Error Resume Next
  415.     Dim msoBarPos As Office.MsoBarPosition
  416.     Dim strToolbarName As String
  417.     strToolbarName = mnuViewToolbar(Index).Caption
  418.     With mDoc.CommandBars(strToolbarName)
  419.         .Enabled = True ' ToolBar must be Enabled before it can be made Visible
  420.         .Visible = Not .Visible
  421.         mnuViewToolbar(Index).Checked = .Visible
  422.         
  423.         If .Visible Then
  424.         
  425.             Select Case strToolbarName
  426.             
  427.                 Case "Drawing"
  428.                     msoBarPos = msoBarBottom
  429.                     
  430.                 Case "Reviewing"
  431.                     msoBarPos = msoBarRight
  432.                     
  433.                 Case Else
  434.                     msoBarPos = msoBarTop
  435.             End Select
  436.             
  437.             .Position = msoBarPos
  438.         End If
  439.         
  440.     End With
  441. End Sub
  442. Private Sub mnuToolsMenu_Click()
  443.     On Error Resume Next
  444.     With mDoc
  445.         mnuTools(TOOLS_SPELL) = Not .SpellingChecked
  446.         
  447.         With .Application.Selection ' restrict to one word only
  448.             mnuTools(TOOLS_THESAURUS) = (.Type = wdSelectionNormal) _
  449.                                     And (.Words.Count = 1)
  450.         End With
  451.         
  452.     End With
  453. End Sub
  454. Private Sub mnuTools_Click(Index As Integer)
  455.     On Error Resume Next
  456.     Select Case Index
  457.         Case TOOLS_SPELL
  458.             mDoc.CheckSpelling
  459.         
  460.         Case TOOLS_THESAURUS
  461.             mDoc.Application.Selection.Range.CheckSynonyms
  462.             
  463.         Case TOOLS_OPTIONS
  464.             mnuOpt(OPT_SHOWALL).Checked = mDoc.ActiveWindow.View.ShowAll
  465.             mnuOpt(OPT_STATUSBAR).Checked = sta.Visible
  466.             
  467.     End Select
  468. End Sub
  469. Private Sub mnuOpt_Click(Index As Integer)
  470.     On Error Resume Next
  471.     Dim blnChecked As Boolean
  472.     With mnuOpt(Index)
  473.         .Checked = Not .Checked
  474.         blnChecked = .Checked
  475.     End With
  476.     Select Case Index
  477.         Case OPT_SHOWALL
  478.             mDoc.ActiveWindow.View.ShowAll = blnChecked
  479.            
  480.         Case OPT_STATUSBAR
  481.             sta.Visible = blnChecked
  482.             SetBotUsedArea
  483.             
  484.     End Select
  485. End Sub
  486. Private Sub wbr_DocumentComplete(ByVal pDisp As Object, URL As Variant)
  487.     On Error GoTo DocumentComplete_Error
  488.     mnuDemoMenu = False '<== Demo
  489.     If pDisp Is wbr.Object Then
  490.         mnuViewMenu = TypeOf wbr.Document Is Word.Document
  491.         mnuToolsMenu = mnuViewMenu
  492.         
  493.         If mnuViewMenu Then
  494.             Set mDoc = wbr.Document
  495.             mDocURL = URL
  496.             sta.SimpleText = "Done"
  497.             '<== Demo
  498.             mnuDemoMenu = InStr(1, URL, DEMO_DOC, vbTextCompare)
  499.             mnuDemo(DEMO_TITLE) = mnuDemoMenu
  500.             mnuDemo(DEMO_SUBTITLE) = mnuDemoMenu
  501.             mnuDemo(DEMO_DATA) = mnuDemoMenu
  502.             mnuDemo(DEMO_NOTES) = mnuDemoMenu
  503.             mnuDemo(DEMO_ALL) = mnuDemoMenu
  504.             '<== Demo
  505.         Else
  506.             Set mDoc = Nothing
  507.             mDocURL = vbNullString
  508.         End If
  509.         
  510.         mnuFile(FILE_FORMAT).Visible = InStr(1, URL, "about:", vbTextCompare)   '<== Demo
  511.    End If
  512. DocumentComplete_Exit:
  513.     Exit Sub
  514. DocumentComplete_Error:
  515.     MsgBox Err.Number & " - " & Err.Description, vbExclamation, _
  516.                 Me.Name & ".DocumentComplete"
  517.     Resume DocumentComplete_Exit
  518. End Sub
  519. Private Sub wbr_StatusTextChange(ByVal Text As String)
  520.     sta.SimpleText = Text
  521. End Sub
  522. Private Sub FileSaveAsHTML()
  523. ' This can also be done with the "SaveAs" option.
  524. ' Note that ConvHTML.SaveDocAsHTML could be used to convert a
  525. ' document to HTML withtout user intervention if parameters
  526. ' are provided by some other means.
  527.     On Error GoTo FileSaveAsHTML_Error
  528.     Dim FileName As String
  529.     Dim lngPos As Long
  530.     Dim strResult As String
  531.     Dim strMsg As String
  532.     Dim lngStyle As VbMsgBoxStyle
  533.     lngPos = InStrRev(mDocURL, "\", , vbTextCompare)
  534.     If lngPos Then
  535.         FileName = Mid$(mDocURL, lngPos + 1)
  536.         FileName = Split(FileName, ".")(0) & ".html"
  537.         FileName = LCase$(FileName)
  538.     End If
  539.     strResult = FileDlgs.GetSaveAsFileName( _
  540.                     FileName, _
  541.                     App.Path, _
  542.                     "HTML Document (*.htm;*.html):*.htm;*.html")
  543.                     
  544.     If Len(strResult) Then
  545.         FileName = ConvHTML.SaveDocAsHTML( _
  546.                     Doc:=mDoc, _
  547.                     NewFileName:=strResult)
  548.         If Len(FileName) Then
  549.             strMsg = mDocURL & vbNewLine & vbNewLine _
  550.                     & vbTab & "saved in HTML format as" & vbNewLine & vbNewLine _
  551.                     & FileName
  552.             lngStyle = vbInformation
  553.         Else
  554.             strMsg = "ERROR: Save operation failed"
  555.             lngStyle = vbExclamation
  556.         End If
  557.         MsgBox strMsg, lngStyle, "Save As HTML"
  558.     End If
  559. FileSaveAsHTML_Exit:
  560.     Exit Sub
  561. FileSaveAsHTML_Error:
  562.     MsgBox Err.Number & " - " & Err.Description, vbExclamation, _
  563.                 Me.Name & ".FileSaveAsHTML"
  564.     Resume FileSaveAsHTML_Exit
  565. End Sub
  566. Private Sub SetBotUsedArea()
  567.     With sta
  568.         .Refresh
  569.         mBotUsedArea = IIf(.Visible, .Height + MARGIN, MARGIN)
  570.     End With
  571.     mVertUsedArea = mTopUsedArea + mBotUsedArea
  572.     Form_Resize
  573. End Sub
  574. '<== Demo additions ==================================================
  575. Private Sub mnuDemo_Click(Index As Integer)
  576. '   Manipulates DEMO_DOC using pre-defined BookMarks
  577.     On Error GoTo mnuDemo_Error
  578.     Dim MenuCaption As String
  579.     MenuCaption = "mnuDemo(" & Index & ") - " & mnuDemo(Index).Caption
  580.     sta.SimpleText = MenuCaption
  581.     Select Case Index
  582.         Case DEMO_TITLE
  583.             mDoc.Bookmarks("BMTitle").Range.InsertAfter ("This is the Title")
  584.             
  585.         Case DEMO_SUBTITLE
  586.            mDoc.Bookmarks("BMSubTitle").Range.InsertAfter ("This is the Sub-title")
  587.            
  588.         Case DEMO_DATA
  589.            InsertData DataFileName:=mFilePath & DEMO_DAT
  590.            
  591.         Case DEMO_NOTES
  592.             With mDoc.Bookmarks("BMNotes").Range
  593.                 .InsertAfter _
  594.                     Text:="Explanatory notes go here" & vbNewLine _
  595.                         & "and can be as many lines as necessary." _
  596.                         & vbNewLine & vbNewLine _
  597.                         & "Or perhaps a Text Box could be defined for the user " _
  598.                         & "to enter comments before printing."
  599.             End With
  600.                     
  601.          Case DEMO_ALL
  602.             AutoSequence    ' = all of the above !!
  603.             
  604.     End Select
  605.     mDoc.Application.Selection.GoTo what:=wdGoToBookmark, Name:="BMTop"
  606. mnuDemo_Exit:
  607.     mnuDemo(Index) = False
  608.     mnuDemo(DEMO_ALL) = False
  609.     sta.SimpleText = vbNullString
  610.     Exit Sub
  611. mnuDemo_Error:
  612.     MsgBox Err.Number & " - " & Err.Description, vbExclamation, _
  613.                     Me.Name & "." & MenuCaption
  614.     Resume mnuDemo_Exit
  615. End Sub
  616. Private Sub InsertData(DataFileName As String)
  617. ' Inserts the contents of file DEMO_DAT
  618. ' and formats resultant text as a Word Table
  619.     On Error GoTo InsertData_Error
  620.     Dim rng As Word.Range
  621.     With mDoc.Application.Selection  ' insert data after Bookmark
  622.         .GoTo what:=wdGoToBookmark, Name:="BMData"
  623.         .MoveDown
  624.         Set rng = .Range    ' for repositoning after Insert
  625.         .InsertFile FileName:=DataFileName
  626.     End With
  627.     rng.Select
  628.     With mDoc.Application.Selection  ' format data as Table
  629.         .MoveDown Unit:=wdLine, Count:=4, Extend:=wdExtend
  630.         .ConvertToTable _
  631.             Separator:=wdSeparateByTabs, _
  632.             AutoFit:=False
  633.         .Tables(1).AutoFormat _
  634.             Format:=wdTableFormatColorful2, _
  635.             AutoFit:=False
  636.     End With
  637. InsertData_Exit:
  638.     Exit Sub
  639. InsertData_Error:
  640.     MsgBox Err.Number & " - " & Err.Description, vbExclamation, _
  641.                 Me.Name & ".InsertData"
  642.     Resume InsertData_Exit
  643. End Sub
  644. Private Sub AutoSequence()
  645.     On Error GoTo AutoSequence_Exit
  646.     mnuDemoMenu = False
  647.     mDoc.Application.ScreenUpdating = False
  648.     mnuDemo_Click DEMO_TITLE
  649.     mnuDemo_Click DEMO_SUBTITLE
  650.     mnuDemo_Click DEMO_DATA
  651.     mnuDemo_Click DEMO_NOTES
  652. AutoSequence_Exit:
  653.     mDoc.Application.ScreenUpdating = True
  654. End Sub
  655. Private Sub FormatTitlePage()   ' Late-binding
  656. ' This little bit of nonsense demonstrates the manipulation of
  657. ' an HTML Document Object contained by a WebBrowser Control.
  658. ' Recommended method is to set a "Project/References" to
  659. '       "Microsoft HTML Object Library" (mshtml.dll)
  660. ' and use strictly-typed objects for early-binding.
  661. ' That also makes Tools/Options/Editor/Auto List Members available in the IDE.
  662.     On Error GoTo FormatTitlePage_Error
  663.     Const strHR = "<HR style=color:cyan;width:300>"
  664.     With wbr.Document.body
  665.         With .Style
  666.             .backgroundcolor = "#689CD0"
  667.             .Color = "white"
  668.             .fontfamily = "Comic Sans MS"
  669.             .FontSize = "48pt"
  670.             .TextAlign = "center"
  671.         End With
  672.         
  673.         With .All.idDIV
  674.             .innerHTML = "Automation<BR>Demonstration"  ' multiple-statements
  675.             .insertAdjacentHTML "BeforeBegin", strHR    ' to demonstrate more
  676.             .insertAdjacentHTML "AfterEnd", strHR       ' avaliable functions.
  677.             
  678.             With .Style
  679.                 .Color = "yellow"
  680.                 .fontfamily = "serif"
  681.                 .FontSize = "32pt"
  682.             End With
  683.             
  684.         End With
  685.         
  686.     End With
  687. FormatTitlePage_Exit:
  688.     Exit Sub
  689. FormatTitlePage_Error:
  690.     MsgBox Err.Number & " - " & Err.Description, vbExclamation, _
  691.                 Me.Name & ".FormatTitlePage"
  692.     Resume FormatTitlePage_Exit
  693. End Sub
  694.